//
//  ViewController.m
//  webview
//
//  Created by 蓓蕾 on 2022/2/11.
//

#import "ViewController.h"
#import "QuestionView.h"
#import <AFNetworking.h>

@interface ViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UILabel *titleView;

@property (nonatomic, strong) UIView *answerView;

@property (nonatomic, assign) NSInteger currentAnswerIndex;

@property (nonatomic, strong) NSMutableArray *questionSource;

@property (nonatomic, strong) NSMutableArray *selectTitleArr;

@property (nonatomic, strong) NSMutableArray *selectAnswerArr;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLOR(0xF3EEEF);
    [self initUI];
    [self getQuestionData];
    NSLog(@"成功启动");
}

-(void)initUI
{
    
    UIButton *previousView = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:previousView];
    [previousView setTitle:@"上一步" forState:UIControlStateNormal];
    [previousView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [previousView addTarget:self action:@selector(previousMethod) forControlEvents:UIControlEventTouchUpInside];
    previousView.titleLabel.font = [UIFont systemFontOfSize:20];
    previousView.backgroundColor = [UIColor orangeColor];
    previousView.layer.cornerRadius = 10;
    [previousView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.view.mas_centerX).mas_offset(-5);
        make.bottom.mas_equalTo(self.view.mas_bottom).mas_offset(-20);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *nextView = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:nextView];
    [nextView setTitle:@"下一步" forState:UIControlStateNormal];
    [nextView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [nextView addTarget:self action:@selector(nextMethod) forControlEvents:UIControlEventTouchUpInside];
    nextView.titleLabel.font = [UIFont systemFontOfSize:20];
    nextView.backgroundColor = [UIColor orangeColor];
    nextView.layer.cornerRadius = 10;
    [nextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.view.mas_right).mas_offset(-20);
        make.left.mas_equalTo(self.view.mas_centerX).mas_offset(5);
        make.bottom.mas_equalTo(previousView.mas_bottom).mas_offset(0);
        make.height.mas_equalTo(50);
    }];
    
    _scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:_scrollView];
//    _scrollView.backgroundColor = [UIColor purpleColor];
    [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).mas_offset(0);
        make.top.mas_equalTo(self.view.mas_top).mas_offset(80);
        make.width.mas_equalTo(kScreenWidth);
        make.height.mas_equalTo(kScreenHeight - 100 - 80);
    }];
    
    _titleView = [[UILabel alloc] init];
    [_scrollView addSubview:_titleView];
    _titleView.text = @"标题";
    _titleView.font = [UIFont systemFontOfSize:15];
    _titleView.textColor = [UIColor blackColor];
    _titleView.numberOfLines = 0;
    [_titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).mas_offset(20);
        make.right.mas_equalTo(self.view.mas_right).mas_offset(-20);
        make.top.mas_equalTo(_scrollView.mas_top).mas_offset(0);
    }];
    
    _answerView = [[UIView alloc] init];
    [_scrollView addSubview:_answerView];
    [_answerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).mas_offset(0);
        make.right.mas_equalTo(self.view.mas_right).mas_offset(0);
        make.top.mas_equalTo(_titleView.mas_bottom).mas_offset(20);
        make.bottom.mas_equalTo(_scrollView.mas_bottom).mas_offset(-20);
    }];
}

-(void)previousMethod
{
    if (_currentAnswerIndex > 0) {
        _currentAnswerIndex--;
        [self updateAnswerView];
    }
    else
    {
        NSLog(@"已经是第一题了");
    }
}

-(void)nextMethod
{
    if (_currentAnswerIndex < _questionSource.count - 1) {
        if (self.selectAnswerArr.count == 0) {
            NSLog(@"请先回答问题，再进入下一题");
            return;
        }
        NSMutableDictionary *currentAnswerDic = [NSMutableDictionary new];
        for (QuestionView *itemView in self.selectAnswerArr) {
            NSLog(@"%@ = %@",itemView.titleString,itemView.selectSubAnswers);
            currentAnswerDic[itemView.titleString] = itemView.selectSubAnswers;
        }
        NSDictionary *currentQuestionDic = _questionSource[_currentAnswerIndex];
        NSMutableDictionary *tempQuestionDic = [NSMutableDictionary dictionaryWithDictionary:currentQuestionDic];
        tempQuestionDic[@"answerKey"] = currentAnswerDic;
        [_questionSource replaceObjectAtIndex:_currentAnswerIndex withObject:tempQuestionDic];
        _currentAnswerIndex++;
        [self updateAnswerView];
    }
    else
    {
        NSLog(@"已经是最后一题了");
        NSMutableDictionary *currentAnswerDic = [NSMutableDictionary new];
        for (QuestionView *itemView in self.selectAnswerArr) {
            NSLog(@"%@ = %@",itemView.titleString,itemView.selectSubAnswers);
            currentAnswerDic[itemView.titleString] = itemView.selectSubAnswers;
        }
        NSDictionary *currentQuestionDic = _questionSource[_currentAnswerIndex];
        NSMutableDictionary *tempQuestionDic = [NSMutableDictionary dictionaryWithDictionary:currentQuestionDic];
        tempQuestionDic[@"answerKey"] = currentAnswerDic;
        [_questionSource replaceObjectAtIndex:_currentAnswerIndex withObject:tempQuestionDic];
    }
}

-(void)updateAnswerView//:(NSDictionary *)answerDic
{
    [self.selectAnswerArr removeAllObjects];
    NSLog(@"self.selectAnswerArr.count = %ld",self.selectAnswerArr.count);
    MJWeakSelf
    UIView *lastView;
    NSDictionary *answerDic = _questionSource[_currentAnswerIndex];
    NSDictionary *oldAnswerDic = answerDic[@"answerKey"];
    NSArray *oldAnswerArr = [oldAnswerDic allKeys];
    NSString *titleString = answerDic[@"describe"];
    _titleView.text = titleString;
    NSArray *answerArr = answerDic[@"option"];
    for (UIView *subView in [_answerView subviews]) {
        [subView removeFromSuperview];
    }
    NSDictionary *optionLevelInfo = answerDic[@"optionLevelInfo"];
    for (NSInteger i = 0; i < answerArr.count; ++i) {
        NSString *titleString = answerArr[i];
        QuestionView *questionView = [[QuestionView alloc] init];
        [_answerView addSubview:questionView];
        questionView.titleString = titleString;
        NSDictionary *levelInfo = optionLevelInfo[titleString];
        questionView.subAnswerInfo = levelInfo;
        questionView.selectBgColor = [UIColor orangeColor];
        questionView.normalBgColor = [UIColor whiteColor];
        questionView.selectTextColor = [UIColor whiteColor];
        questionView.normalTextColor = [UIColor blackColor];
        questionView.optionItemCornerRadio = 10;
        questionView.level = 1;
        if ([oldAnswerArr containsObject:titleString]) {
            NSArray *oldSubAnswerArr = oldAnswerDic[titleString];
            questionView.selectSubAnswers = [NSMutableArray arrayWithArray:oldSubAnswerArr];
            questionView.isSelected = YES;
            [weakSelf.selectAnswerArr addObject:questionView];
            
        }
        else
        {
            questionView.isSelected = NO;
        }
        if (lastView) {
//            questionView.backgroundColor = [UIColor magentaColor];
            [questionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.view.mas_left).mas_offset(20);
                make.right.mas_equalTo(self.view.mas_right).mas_offset(-20);
                make.top.mas_equalTo(lastView.mas_bottom).mas_offset(0);
            }];
        }
        else
        {
//            questionView.backgroundColor = [UIColor purpleColor];
            [questionView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(self.view.mas_left).mas_offset(20);
                make.right.mas_equalTo(self.view.mas_right).mas_offset(-20);
                make.top.mas_equalTo(_answerView.mas_top).mas_offset(0);
            }];
        }
        lastView = questionView;
        questionView.SelectAnswerItemBlock = ^(QuestionView * _Nonnull objectView) {
            NSDictionary *currentQuestionDic = weakSelf.questionSource[weakSelf.currentAnswerIndex];
            NSInteger is_dx = [currentQuestionDic[@"is_dx"] integerValue];
            NSInteger num = [currentQuestionDic[@"is_dx"] integerValue];
            if (is_dx == 1) {//单选
                for (QuestionView *currentQuestionView in [weakSelf.answerView subviews]) {
                    if (objectView == currentQuestionView) {
                        currentQuestionView.isSelected = YES;
                    }
                    else
                    {
                        currentQuestionView.isSelected = NO;
                    }
                }
                [weakSelf.selectAnswerArr removeAllObjects];
                [weakSelf.selectAnswerArr addObject:objectView];
            }
            else
            {//多选
                if (weakSelf.selectAnswerArr.count >= num) {
                    
                    if (objectView.isSelected) {
                        objectView.isSelected = NO;
                        if ([weakSelf.selectAnswerArr containsObject:objectView]) {
                            [weakSelf.selectAnswerArr removeObject:objectView];
                        }
                    }
                    else
                    {
                        NSLog(@"最多选择 %ld 项",num);
                    }
                }
                else
                {
                    if (objectView.isSelected) {
                        objectView.isSelected = NO;
                        if ([weakSelf.selectAnswerArr containsObject:objectView]) {
                            [weakSelf.selectAnswerArr removeObject:objectView];
                        }
                    }
                    else
                    {
                        objectView.isSelected = YES;
                        if (![weakSelf.selectAnswerArr containsObject:objectView]) {
                            [weakSelf.selectAnswerArr addObject:objectView];
                        }
                    }
                }
            }
        };
    }
    if (lastView) {
        [_answerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(lastView.mas_bottom).mas_offset(20);
        }];
    }
}

-(void)getQuestionData
{
    
    
    
    
    _questionSource = [NSMutableArray array];
    
    
    
    
    NSMutableDictionary *questionDic = [NSMutableDictionary new];
    questionDic[@"describe"] = @"问题描述";
//    questionDic[@"answerKey"] = @{};//回答过的数据，这个不需要填充数据，在用户选择的过程中，会自动填充数据
    questionDic[@"is_dx"] = @"2";//最多选择几个
    questionDic[@"optionLevelInfo"] = @{@"1":@{@"options":@[@"是", @"否"], @"is_dx":@"1"},
                                        @"2":@{@"options":@[@"是不是", @"难道不是"], @"is_dx":@"2"}
    };//二级选项 - 可为空
    questionDic[@"option"] = @[@"1", @"2",@"3"];//
    
    NSMutableDictionary *questionDic1 = [NSMutableDictionary new];
    questionDic1[@"describe"] = @"第二个问题描述";
    questionDic1[@"is_dx"] = @"1";//最多选择几个
    questionDic1[@"option"] = @[@"这个是单选哦", @"不需要多选",@"你想选哪个"];//
    
    NSMutableDictionary *questionDic2 = [NSMutableDictionary new];
    questionDic2[@"describe"] = @"第三个个问题描述，这个描述会稍微长一点点，你可以慢慢看，也可以跳跃着看，随你喜好哦";
    questionDic2[@"is_dx"] = @"3";//最多选择几个
    questionDic2[@"option"] = @[@"这个是多选哦", @"需要多选",@"你想选哪几个", @"选A", @"还是", @"宣布", @"选B"];//
    
    
    
    [_questionSource addObject:questionDic];
    [_questionSource addObject:questionDic1];
    [_questionSource addObject:questionDic2];
    
    [self updateAnswerView];
    
    
    
//    MJWeakSelf
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    manager.requestSerializer.timeoutInterval = 5 * 60.0f;
//    [manager POST:@"https://www.titaids.com/api/text/one/questionsv2" parameters:nil headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        id jsons = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers  error:nil];
//        NSLog(@"jsons = %@",jsons);
//        NSArray *values = jsons[@"values"];
//        [self detailDataSource:values];
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        NSLog(@"请求失败");
//
//    }];
}

//-(void)detailDataSource:(NSArray *)dataArr
//{
//    NSMutableArray *tempArr = [NSMutableArray new];
//    for (NSInteger i = 0; i < dataArr.count; ++i) {
//        NSDictionary *answerDic = dataArr[i];
//        NSMutableDictionary *tempAnswerDic = [NSMutableDictionary dictionaryWithDictionary:answerDic];
//        NSArray *optionLevelArr = answerDic[@"option_level"];
//        if ([optionLevelArr isKindOfClass:[NSArray class]] && optionLevelArr.count > 0) {
//            NSMutableDictionary *optionLevelInfo = [NSMutableDictionary new];
//            for (NSDictionary *optionLevelDic in optionLevelArr) {
//                NSString *optionName = optionLevelDic[@"option_name"];
////                NSArray *options = optionLevelDic[@"options"];
////                NSMutableDictionary *optionsInfo = [NSMutableDictionary new];
////                optionsInfo[@"info"] = optionLevelDic
//                optionLevelInfo[optionName] = optionLevelDic;
//            }
//            tempAnswerDic[@"optionLevelInfo"] = optionLevelInfo;
//        }
//        [tempArr addObject:tempAnswerDic];
//    }
//    NSDictionary *lastObject = [tempArr lastObject];
//    [tempArr removeLastObject];
//    [tempArr insertObject:lastObject atIndex:2];
//    NSLog(@"处理过后的数据：");
//    NSLog(@"tempArr = %@",tempArr);
//    _questionSource = [NSMutableArray arrayWithArray:tempArr];
//    [self updateAnswerView];
//}

-(NSMutableArray *)selectAnswerArr
{
    if (!_selectAnswerArr) {
        _selectAnswerArr = [NSMutableArray new];
    }
    return _selectAnswerArr;
}

@end























////
////  ViewController.m
////  webview
////
////  Created by 蓓蕾 on 2022/2/11.
////
//
//#import "ViewController.h"
//
//#import <AFNetworking.h>
//
//#import <WebKit/WebKit.h>
//
//@interface ViewController ()<WKNavigationDelegate>
//@property (nonatomic, strong) WKWebView *webView;
//
//@end
//
//@implementation ViewController
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    NSLog(@"成功启动");
//}
//
//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    NSMutableDictionary *parama = [NSMutableDictionary new];
//    parama[@"username"] = @"17346505243";
//    parama[@"password"] = @"123456qq";
//    parama[@"scope"] = @"ui";
//    parama[@"grant_type"] = @"levelpassword";
//    parama[@"client_id"] = @"browser";
//    parama[@"level"] = @"2";
//    
//    
//    
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    manager.requestSerializer.timeoutInterval = 30.0f;
////    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
////    [manager.requestSerializer setValue:@"Basic YnJvd3NlcjoxMjM0NTY=" forHTTPHeaderField:@"Authorization"];
////    URLString = [NSString stringWithFormat:@"%@%@",BaseUrl,URLString];
//    [manager POST:@"http://123.60.5.200:20003/api/uaa/oauth/token" parameters:parama headers:@{@"Authorization":@"Basic YnJvd3NlcjoxMjM0NTY="} progress:^(NSProgress * _Nonnull uploadProgress) {
//        
//    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        id jsons = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers  error:nil];
//        NSLog(@"jsons = %@",jsons);
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        NSLog(@"error = %@",error.localizedDescription);
//    }];
//    
////    [manager POST:@"http://123.60.5.200:20003/api/uaa/oauth/token" parameters:parama headers:nil progress:^(NSProgress * _Nonnull uploadProgress) {
////    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
////        NSLog(@"%@",responseObject);
////
////        }
////    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
////        NSLog(@"error = %@",error.localizedDescription);
////
////    }];
//    
//}
//
//
//@end



























////
////  ViewController.m
////  webview
////
////  Created by 蓓蕾 on 2022/2/11.
////
//
//#import "ViewController.h"
//
//#import <AFNetworking.h>
//
//#import <WebKit/WebKit.h>
//
//#import <TZImagePickerController.h>
//
//@interface ViewController ()<WKNavigationDelegate, TZImagePickerControllerDelegate>
//@property (nonatomic, strong) WKWebView *webView;
//
//@end
//
//@implementation ViewController
//
//- (void)viewDidLoad {
//    [super viewDidLoad];
//    // Do any additional setup after loading the view.
//
//    NSLog(@"成功启动");
//    return;
//    _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
//    [self.view addSubview:_webView];
//    _webView.navigationDelegate = self;
//
////    NSString *htmlString = @"<p>良好的肩部静态位置，基本位于在胸廓的正上方，手臂自然垂于身体两侧。<img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299738388167.png\"/></p><p></p><p><br/></p><p>从上往下俯视，锁骨和肩胛骨大致成一个：前后对称的V形，架在胸廓的正上方。</p><p><br/></p><p><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299334592058.png\" title=\"1644299334592058.png\" alt=\"肩部-俯视.png\"/></p><p><br/></p><p>理想的肩部位置，是肩部高效安全运动的基础。</p><p><br/></p><p>肩部位置的偏移，可能引起：肩部劳损不适、运动损伤、拜拜肉堆积、腋窝赘肉、假性副乳、上斜方肌过度代偿等问题。</p><p><br/></p><p>常见的位置偏移：圆肩/肩部内扣、肱骨前移；</p><p><br/></p><p style=\"text-align: center;\"><strong><span style=\"color: rgb(0, 112, 192);\">以下是您的评估结果</span></strong></p><p><br/></p><hr/><p><br/></p>";
//
//
////    <html><head><meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'/}><meta content=\'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;\' name=\'viewport\' /><meta name=\'apple-mobile-web-app-capable\' content=\'yes\'><meta name=\'apple-mobile-web-app-status-bar-style\' content=\'black\'><link rel=\'stylesheet\' type=\'text/css\' /><style type=\'text/css\'> .color{color:#576b95;}</style></head><body><div id=\'content\'><p>良好的肩部静态位置，基本位于在胸廓的正上方，手臂自然垂于身体两侧。</p><p>{margin:0px; padding:0px}</p><p { margin: 0; padding: 0; height:220px;}><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299738388167.png\"/></p><p></p><p><br/></p><p>从上往下俯视，锁骨和肩胛骨大致成一个：前后对称的V形，架在胸廓的正上方。</p><p><br/></p><p><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299334592058.png\" title=\"1644299334592058.png\" alt=\"肩部-俯视.png\"/></p><p><br/></p><p>理想的肩部位置，是肩部高效安全运动的基础。</p><p><br/></p><p>肩部位置的偏移，可能引起：肩部劳损不适、运动损伤、拜拜肉堆积、腋窝赘肉、假性副乳、上斜方肌过度代偿等问题。</p><p><br/></p><p>常见的位置偏移：圆肩/肩部内扣、肱骨前移；</p><p><br/></p><p style=\"text-align: center;\"><strong><span style=\"color: rgb(0, 112, 192);\">以下是您的评估结果</span></strong></p><p><br/></p><hr/><p><br/></p>
//
//    NSString *htmlString = @"<p>良好的肩部静态位置，基本位于在胸廓的正上方，手臂自然垂于身体两侧。</p><p><br/></p><p { margin: 0; padding: 0; height:220px;}><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299738388167.png\"/></p><p></p><p><br/></p><p>从上往下俯视，锁骨和肩胛骨大致成一个：前后对称的V形，架在胸廓的正上方。</p><p><br/></p><p><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299334592058.png\" title=\"1644299334592058.png\" alt=\"肩部-俯视.png\"/></p><p><br/></p><p>理想的肩部位置，是肩部高效安全运动的基础。</p><p><br/></p><p>肩部位置的偏移，可能引起：肩部劳损不适、运动损伤、拜拜肉堆积、腋窝赘肉、假性副乳、上斜方肌过度代偿等问题。</p><p><br/></p><p>常见的位置偏移：圆肩/肩部内扣、肱骨前移；</p><p><br/></p><p style=\"text-align: center;\"><strong><span style=\"color: rgb(0, 112, 192);\">以下是您的评估结果</span></strong></p><p><br/></p><hr/><p><br/></p>";
//
////    NSString *htmlString = @"<p>良好的肩部静态位置，基本位于在胸廓的正上方，手臂自然垂于身体两侧。</p><p><br/></p><p><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299738388167.png\"/></p><p><br/></p><p>从上往下俯视，锁骨和肩胛骨大致成一个：前后对称的V形，架在胸廓的正上方。</p><p><br/></p><p><img src=\"https://www.titaids.com/ueditor/php/upload/image/20220208/1644299334592058.png\" title=\"1644299334592058.png\" alt=\"肩部-俯视.png\"/></p><p><br/></p><p>理想的肩部位置，是肩部高效安全运动的基础。</p><p><br/></p><p>肩部位置的偏移，可能引起：肩部劳损不适、运动损伤、拜拜肉堆积、腋窝赘肉、假性副乳、上斜方肌过度代偿等问题。</p><p><br/></p><p>常见的位置偏移：圆肩/肩部内扣、肱骨前移；</p><p><br/></p><p style=\"text-align: center;\"><strong><span style=\"color: rgb(0, 112, 192);\">以下是您的评估结果</span></strong></p><p><br/></p><hr/><p><br/></p>";
//    NSString *result = [NSString stringWithFormat:@"<%@ %@",@"img",@"style='display: block; max-width: 100%;'"];
//    htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<img" withString:result];
//
////    NSString *htmlStr = [NSString stringWithFormat:@"<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>img{max-width: 100%%; width:100%%; height:auto;}*{margin:0px;}</style></head><body><div id=\'content\'>%@</div></body></html>", htmlString];
//
//    NSString *htmlStr = [NSString stringWithFormat:@"<html><head><meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'/}><meta content=\'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;\' name=\'viewport\' /><style>*{margin:0px;}</style><meta name=\'apple-mobile-web-app-capable\' content=\'yes\'><meta name=\'apple-mobile-web-app-status-bar-style\' content=\'black\'><link rel=\'stylesheet\' type=\'text/css\' /><style type=\'text/css\'> .color{color:#576b95;}</style></head><body><div id=\'content\'>%@</div>", htmlString];
//    [_webView loadHTMLString:htmlStr baseURL:nil];
//}
//
//#pragma mark ---------------- WKNavigationDelegate ----------------
//- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation {
//
////    //禁止用户选择
////    [webView evaluateJavaScript:@"document.documentElement.style.webkitUserSelect='none';" completionHandler:nil];
////    [webView evaluateJavaScript:@"document.activeElement.blur();" completionHandler:nil];
////    // 适当增大字体大小
////    [webView evaluateJavaScript:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'" completionHandler:nil];
//
////    if (_webViewBgColor) {
////        [webView evaluateJavaScript:[NSString stringWithFormat:@"document.body.style.backgroundColor=\"%@\"",_webViewBgColor] completionHandler:nil];
////    }
////    [webView evaluateJavaScript:[NSString stringWithFormat:@"document.body.style.backgroundColor=\"#ff4789\""] completionHandler:nil];
//    __weak typeof(self) weakSelf = self;
//    //获取内容实际高度（像素）@"document.getElementById(\"content\").offsetHeight;"
//    [webView evaluateJavaScript:@"document.body.scrollHeight" completionHandler:^(id _Nullable result,NSError * _Nullable error) {
//        CGFloat height = [result floatValue];
//        CGRect webViewRect = weakSelf.webView.frame;
//        webViewRect.size.height = height;
//        webViewRect.origin.y = 0;
////        NSLogCGRect(weakSelf.titleView.frame);
////        weakSelf.webView.frame = webViewRect;//CGRectMake(0, CGRectGetMaxY(weakSelf.titleView.frame), kScreenWidth, height);
////        [weakSelf.webView mas_updateConstraints:^(MASConstraintMaker *make) {
////            make.height.mas_equalTo(height);
////        }];
//        NSLog(@"height = %f", height);
//
//    }];
//
//    NSLog(@"结束加载");
//}
//
//-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
//    __weak typeof(self)weakSelf = self;
//    UIAlertAction* fromPhotoAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault                                                                 handler:^(UIAlertAction * action) {
//        TZImagePickerController *pickerController = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
//        [self presentViewController:pickerController animated:YES completion:nil];
//    }];
//    UIAlertAction* fromCameraAction = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault                                                             handler:^(UIAlertAction * action) {
////        [weakSelf selectTakePhoto];
//    }];
//    [alertController addAction:cancelAction];
//    [alertController addAction:fromCameraAction];
//    [alertController addAction:fromPhotoAction];
//    [self presentViewController:alertController animated:YES completion:nil];
//
//
//
////    TZImagePickerController *pickerController = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
////    [self presentViewController:pickerController animated:YES completion:nil];
//}
//
//
//@end
